#include "StdAfx.h"
#include "Matrix4.h"

namespace Math
{

const Matrix4 Matrix4::ZERO(0.0f, 0.0f, 0.0f, 0.0f,
							  0.0f, 0.0f, 0.0f, 0.0f,
							  0.0f, 0.0f, 0.0f, 0.0f,
							  0.0f, 0.0f, 0.0f, 0.0f);

const Matrix4 Matrix4::IDENTITY(1.0f, 0.0f, 0.0f, 0.0f,
								  0.0f, 1.0f, 0.0f, 0.0f,
								  0.0f, 0.0f, 1.0f, 0.0f,
								  0.0f, 0.0f, 0.0f, 1.0f);

//////////////////////////////////////////////////////////////////////////
void Matrix4::Transpose()
{
	float t;

	t = m_M12;	m_M12 = m_M21;	m_M21 = t;
	t = m_M13;	m_M13 = m_M31;	m_M31 = t;
	t = m_M14;	m_M14 = m_M41;	m_M41 = t;

	t = m_M23;	m_M23 = m_M32;	m_M32 = t;		
	t = m_M24;	m_M24 = m_M42;	m_M42 = t;				

	t = m_M34;	m_M34 = m_M43;	m_M43 = t;
}

//////////////////////////////////////////////////////////////////////////
void Matrix4::InvertTransformationMatrix()
{
    float t;

	// transpose 3x3 matrix (invert rotation)
	t = m_M12;	m_M12 = m_M21;	m_M21 = t;
	t = m_M13;	m_M13 = m_M31;	m_M31 = t;
	t = m_M23;	m_M23 = m_M32;	m_M32 = t;		

	// calc translation
	const float x = m_M14;
	const float y = m_M24;
	const float z = m_M34;
	
	m_M14 = -((m_M11 * x) + (m_M12 * y) + (m_M13 * z));
	m_M24 = -((m_M21 * x) + (m_M22 * y) + (m_M23 * z));
	m_M34 = -((m_M31 * x) + (m_M32 * y) + (m_M33 * z));
}

} // namespace Math
